import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:my_flutter_tool/widgets/loaders/dance_loader.dart';
import 'package:my_flutter_tool/widgets/loaders/hor_loader.dart';

///刷新视图
class RefreshView extends StatelessWidget {
  const RefreshView({
    Key key,
    this.child,
    this.onRefresh,
    this.onLoad,
  }) : super(key: key);

  ///子控件
  final Widget child;

  ///刷新
  final Future Function() onRefresh;

  ///加载
  final Future Function() onLoad;

  @override
  Widget build(BuildContext context) {
    return EasyRefresh(
      header: CustomHeader(
          headerBuilder: (
        BuildContext context,
        RefreshMode refreshState,
        double pulledExtent,
        double refreshTriggerPullDistance,
        double refreshIndicatorExtent,
        AxisDirection axisDirection,
        bool float,
        Duration completeDuration,
        bool enableInfiniteRefresh,
        bool success,
        bool noMore,
      ) =>
              const DanceLoader()),
      footer: CustomFooter(
          footerBuilder: (
        BuildContext context,
        LoadMode loadState,
        double pulledExtent,
        double loadTriggerPullDistance,
        double loadIndicatorExtent,
        AxisDirection axisDirection,
        bool float,
        Duration completeDuration,
        bool enableInfiniteLoad,
        bool success,
        bool noMore,
      ) =>
              const HorLoader()),
      child: child,
      onLoad: onLoad,
      onRefresh: onRefresh,
    );
  }
}
